home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / utilities / emulators / apple][ / screen.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  6KB  |  287 lines

  1. /*
  2.  *  a2, an Apple II emulator in C
  3.  *  (c) Copyright 1990 by Rich Skrenta
  4.  *
  5.  *  Command line interface written by Tom Markson
  6.  *
  7.  *  Distribution agreement:
  8.  *
  9.  *    You may freely copy or redistribute this software, so long
  10.  *    as there is no profit made from its use, sale, trade or
  11.  *    reproduction.  You may not change this copyright notice,
  12.  *    and it must be included prominently in any copy made.
  13.  *
  14.  *  Send emulator related mail to:  skrenta@blekko.commodore.com
  15.  *                    skrenta@blekko.uucp
  16.  */
  17.  
  18.  
  19.  
  20. #include    <stdio.h>
  21. #include    "a2.h"
  22.  
  23.  
  24. extern char screen_map[];        /* at the bottom of this file */
  25. extern int text1[];
  26.  
  27.  
  28. int line1[0x400];
  29. int col1[0x400];
  30.  
  31.  
  32. info(s)
  33. char *s;
  34. {
  35.  
  36.     MoveCursor(0, 57);
  37.     printf("%-20s", s);
  38.  
  39.     last_line = -1;
  40.     last_col = -1;
  41.     fflush(stdout);
  42. }
  43.  
  44.  
  45. screen_setup() {
  46. extern int set_text1f();
  47. int line, col;
  48. int addr, base;
  49. int i;
  50.  
  51.     for (i = 0; i < 0x400; i++) {
  52.         line1[i] = -1;
  53.         col1[i] = -1;
  54.     }
  55.  
  56.     mem_set[0x04] = set_text1f;
  57.     mem_set[0x05] = set_text1f;
  58.     mem_set[0x06] = set_text1f;
  59.     mem_set[0x07] = set_text1f;
  60.  
  61.     for (line = 0; line < 24; line++) {
  62.         base = text1[line];
  63.         for (col = 0; col < 40; col++) {
  64.             addr = base + col;
  65.             mem[addr] = 0xA0;
  66.             line1[addr - 0x400] = line;
  67.             col1[addr - 0x400] = col;
  68.         }
  69.     }
  70. }
  71.  
  72.  
  73. int last_line = -1;
  74. int last_col = -1;
  75.  
  76.  
  77. #define appleout(n)    if (n >= 0x80) putchar(screen_map[n]); else { StartInverse(); putchar(screen_map[n]); EndInverse(); }
  78.  
  79.  
  80. set_text1f(addr, n)
  81. unsigned short addr;
  82. unsigned char n;
  83. {
  84. int line, col;
  85. unsigned char c;
  86.  
  87.     if (mem[addr] == n)        /* no change, don't do anything */
  88.         return;
  89.  
  90.     mem[addr] = n;
  91.     line = line1[addr - 0x400];
  92.     col = col1[addr - 0x400];
  93.  
  94.     if (line == -1)
  95.         return;
  96.  
  97. /*
  98.  *  Stuff to try to make updating more efficient
  99.  *  Is it really worth it?
  100.  */
  101.  
  102.     if (line == last_line) {
  103.         if (col == 0)
  104.             putchar('\r');
  105.         else switch (col - last_col) {
  106.         case 4:
  107.             c = mem[addr - 3]; appleout(c);
  108.             c = mem[addr - 2]; appleout(c);
  109.             c = mem[addr - 1]; appleout(c);
  110.             break;
  111.         case 3:
  112.             c = mem[addr - 2]; appleout(c);
  113.             c = mem[addr - 1]; appleout(c);
  114.             break;
  115.         case 2:
  116.             c = mem[addr - 1]; appleout(c);
  117.             break;
  118.         case 1:            /* already there */
  119.             break;
  120.         case 0:
  121.             putchar('\b');
  122.             break;
  123.         case -1:
  124.             putchar('\b'); putchar('\b');
  125.             break;
  126.         case -2:
  127.             putchar('\b'); putchar('\b'); putchar('\b');
  128.             break;
  129.         case -3:
  130.             putchar('\b'); putchar('\b'); putchar('\b');
  131.             putchar('\b');
  132.             break;
  133.         default:
  134.             MoveCursor(line, col);
  135.         }
  136.     } else
  137.         MoveCursor(line, col);
  138.  
  139.     appleout(n);
  140.     fflush(stdout);
  141.  
  142.     last_line = line;
  143.     last_col = col;
  144. }
  145.  
  146.  
  147. set_text1(addr, n)
  148. unsigned short addr;
  149. unsigned char n;
  150. {
  151. int line, col;
  152. unsigned char c;
  153.  
  154.     if (mem[addr] == n)        /* no change, don't do anything */
  155.         return;
  156.  
  157.     mem[addr] = n;
  158.     line = line1[addr - 0x400];
  159.     col = col1[addr - 0x400];
  160.  
  161.     if (line == -1)
  162.         return;
  163.  
  164. /*
  165.  *  Stuff to try to make updating more efficient
  166.  *  Is it really worth it?
  167.  */
  168.  
  169.     if (line == last_line) {
  170.         if (col == 0)
  171.             putchar('\r');
  172.         else switch (col - last_col) {
  173.         case 4:
  174.             c = mem[addr - 3]; appleout(c);
  175.             c = mem[addr - 2]; appleout(c);
  176.             c = mem[addr - 1]; appleout(c);
  177.             break;
  178.         case 3:
  179.             c = mem[addr - 2]; appleout(c);
  180.             c = mem[addr - 1]; appleout(c);
  181.             break;
  182.         case 2:
  183.             c = mem[addr - 1]; appleout(c);
  184.             break;
  185.         case 1:            /* already there */
  186.             break;
  187.         case 0:
  188.             putchar('\b');
  189.             break;
  190.         case -1:
  191.             putchar('\b'); putchar('\b');
  192.             break;
  193.         case -2:
  194.             putchar('\b'); putchar('\b'); putchar('\b');
  195.             break;
  196.         case -3:
  197.             putchar('\b'); putchar('\b'); putchar('\b');
  198.             putchar('\b');
  199.             break;
  200.         default:
  201.             MoveCursor(line, col);
  202.         }
  203.     } else
  204.         MoveCursor(line, col);
  205.  
  206.     appleout(n);
  207.  
  208.     last_line = line;
  209.     last_col = col;
  210. }
  211.  
  212.  
  213. redraw_screen() {
  214. int i, j;
  215. unsigned short base;
  216. unsigned char c;
  217.  
  218.     ClearScreen();
  219.     for (i = 0; i < 24; i++) {
  220.         base = text1[i];
  221.         for (j = 0; j < 40; j++) {
  222.             c = mem[base + j];
  223.             appleout(c);
  224.         }
  225.         if (i < 23)
  226.             putchar('\n');
  227.     }
  228.  
  229.     last_line = -1;
  230.     last_col = -1;
  231.  
  232.     fflush(stdout);
  233. }
  234.  
  235.  
  236. /*
  237.  *  Screen display mapping table
  238.  */
  239.  
  240. char screen_map[] = {
  241.  
  242.     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',        /* $00    */
  243.     'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',        /* $08    */
  244.     'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',        /* $10    */
  245.     'X', 'Y', 'Z', '[', '\\',']', '^', '_',        /* $18    */
  246.     ' ', '!', '"', '#', '$', '%', '&', '\'',    /* $20    */
  247.     '(', ')', '*', '+', ',', '-', '.', '/',        /* $28    */
  248.     '0', '1', '2', '3', '4', '5', '6', '7',        /* $30    */
  249.     '8', '9', ':', ';', '<', '=', '>', '?',        /* $38    */
  250.  
  251.     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',        /* $40    */
  252.     'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',        /* $48    */
  253.     'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',        /* $50    */
  254.     'X', 'Y', 'Z', '[', '\\',']', '^', '_',        /* $58    */
  255.     ' ', '!', '"', '#', '$', '%', '&', '\'',    /* $60    */
  256.     '(', ')', '*', '+', ',', '-', '.', '/',        /* $68    */
  257.     '0', '1', '2', '3', '4', '5', '6', '7',        /* $70    */
  258.     '8', '9', ':', ';', '<', '=', '>', '?',        /* $78    */
  259.  
  260.     '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g',        /* $80    */
  261.     'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',        /* $88    */
  262.     'p', 'q', 'r', 's', 't', 'u', 'v', 'w',        /* $90    */
  263.     'x', 'y', 'z', '[', '\\',']', '^', '_',        /* $98    */
  264.     ' ', '!', '"', '#', '$', '%', '&', '\'',    /* $A0    */
  265.     '(', ')', '*', '+', ',', '-', '.', '/',        /* $A8    */
  266.     '0', '1', '2', '3', '4', '5', '6', '7',        /* $B0    */
  267.     '8', '9', ':', ';', '<', '=', '>', '?',        /* $B8    */
  268.  
  269.     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',        /* $C0    */
  270.     'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',        /* $C8    */
  271.     'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',        /* $D0    */
  272.     'X', 'Y', 'Z', '[', '\\',']', '^', '_',        /* $D8    */
  273.     ' ', '!', '"', '#', '$', '%', '&', '\'',    /* $E0    */
  274.     '(', ')', '*', '+', ',', '-', '.', '/',        /* $E8    */
  275.     '0', '1', '2', '3', '4', '5', '6', '7',        /* $F0    */
  276.     '8', '9', ':', ';', '<', '=', '>', '?',        /* $F8    */
  277.  
  278. };
  279.  
  280. int text1[] = {
  281.     0x400, 0x480, 0x500, 0x580, 0x600, 0x680, 0x700, 0x780,
  282.     0x428, 0x4A8, 0x528, 0x5A8, 0x628, 0x6A8, 0x728, 0x7A8,
  283.     0x450, 0x4D0, 0x550, 0x5D0, 0x650, 0x6D0, 0x750, 0x7D0,
  284.     0x478, 0x4F8, 0x578, 0x5F8, 0x678, 0x6F8, 0x778, 0x7F8
  285. };
  286.  
  287.